package com.zrrd.jt_admin.image.controller;


import com.zrrd.jt_admin.common.entity.ImageClass;
import com.zrrd.jt_admin.common.response.ResponseResult;
import com.zrrd.jt_admin.common.page.ImageClassPageVo;
import com.zrrd.jt_admin.image.service.ImageClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wanjl
 * @since 2024-07-03
 */
@Api(tags = "相册分类管理")
@RestController
@RequestMapping("/admin/imageClass")
@ResponseBody
@Slf4j
public class ImageClassController {
    @Resource
    private ImageClassService imageClassService;

    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/{page}")
    @ResponseBody
    public ResponseResult findByPage(@PathVariable("page") int page,
                                     @RequestParam(value = "limit",defaultValue = "10",required = false)Integer limit) {
        log.info("分页查询相册----》");
        ImageClassPageVo pageVo=imageClassService.findByPage(page,limit);

        return ResponseResult.queryResponse(pageVo);
    }

    @ApiOperation(value = "添加", notes = "添加相册分类信息")
    @PostMapping("")
    @ResponseBody
    public ResponseResult add(@RequestBody ImageClass imageClass) {
        boolean flag = imageClassService.save(imageClass);
        return ResponseResult.addResponse(flag);
    }


    @ApiOperation(value = "修改", notes = "修改相册分类信息")
    @PutMapping("")
    @ResponseBody
    public ResponseResult update(@RequestBody ImageClass imageClass) {
        boolean flag = imageClassService.updateById(imageClass);
        return ResponseResult.updateResponse(flag);
    }


    @ApiOperation(value = "删除", notes = "根据id删除")
    @DeleteMapping("/{id}/delete")
    @ResponseBody
    public ResponseResult remove(@PathVariable("id") Integer id) {
        boolean flag = imageClassService.removeById(id);
        return ResponseResult.removeResponse(flag);
    }

}
